import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vite.dev/config/
export default defineConfig({
  plugins: [react()],
  build: {
    rollupOptions: {
      output: {
        manualChunks: (id) => {
          // 将 React 相关库分割到单独的 chunk
          if (id.includes('react') || id.includes('react-dom')) {
            return 'react-vendor';
          }
          // 将 MUI 组件库分割到单独的 chunk
          if (id.includes('@mui/material') || id.includes('@mui/icons-material') || id.includes('@mui/lab')) {
            return 'mui-vendor';
          }
          // 将 Emotion 样式库分割到单独的 chunk
          if (id.includes('@emotion/react') || id.includes('@emotion/styled')) {
            return 'emotion-vendor';
          }
          // 将工具库分割到单独的 chunk
          if (id.includes('axios') || id.includes('zod') || id.includes('zustand') || id.includes('react-hook-form')) {
            return 'utils-vendor';
          }
          // 将 UI 组件库分割到单独的 chunk
          if (id.includes('lucide-react')) {
            return 'ui-vendor';
          }
        },
      },
    },
    // 调整 chunk 大小警告限制（可选）
    chunkSizeWarningLimit: 1000,
  },
})
